using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	public class LibraryVersionControl : FreeFlowAdministrator.VersionControl
	{
    private System.Windows.Forms.Label proceduresLabel;
    private FreeFlowAdministrator.ExtendedDataGrid proceduresGrid;
		private System.ComponentModel.IContainer components = null;

		public LibraryVersionControl()
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.components = new System.ComponentModel.Container();
      this.proceduresLabel = new System.Windows.Forms.Label();
      this.proceduresGrid = new FreeFlowAdministrator.ExtendedDataGrid();
      ((System.ComponentModel.ISupportInitialize)(this.proceduresGrid)).BeginInit();
      this.SuspendLayout();
      // 
      // proceduresLabel
      // 
      this.proceduresLabel.Location = new System.Drawing.Point(8, 224);
      this.proceduresLabel.Name = "proceduresLabel";
      this.proceduresLabel.Size = new System.Drawing.Size(288, 16);
      this.proceduresLabel.TabIndex = 19;
      this.proceduresLabel.Text = "Used in procedure versions:";
      // 
      // proceduresGrid
      // 
      this.proceduresGrid.AllowNavigation = false;
      this.proceduresGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                  | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.proceduresGrid.CaptionVisible = false;
      this.proceduresGrid.DataMember = "";
      this.proceduresGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
      this.proceduresGrid.Location = new System.Drawing.Point(8, 240);
      this.proceduresGrid.Name = "proceduresGrid";
      this.proceduresGrid.Size = new System.Drawing.Size(424, 176);
      this.proceduresGrid.TabIndex = 20;
      // 
      // LibraryVersionControl
      // 
      this.Controls.Add(this.proceduresGrid);
      this.Controls.Add(this.proceduresLabel);
      this.Name = "LibraryVersionControl";
      this.Size = new System.Drawing.Size(592, 424);
      this.Controls.SetChildIndex(this.proceduresLabel, 0);
      this.Controls.SetChildIndex(this.proceduresGrid, 0);
      ((System.ComponentModel.ISupportInitialize)(this.proceduresGrid)).EndInit();
      this.ResumeLayout(false);
      this.PerformLayout();

    }
		#endregion

    public override void LoadVersion(FreeFlow.Administration.Version version)
    {
      base.LoadVersion(version);
      // procedure versions
      proceduresLabel.Visible = (version.Server.SchemaVersion >= SchemaVersion.Version70);
      proceduresGrid.Visible = (version.Server.SchemaVersion >= SchemaVersion.Version70);
      if (version.Server.SchemaVersion >= SchemaVersion.Version70)
      {
        if (version is LibraryVersion)
          proceduresGrid.DataSource = ((LibraryVersion)version).ProcedureVersions;
        proceduresGrid.ClearColumns();
        proceduresGrid.AddColumn("Name");
        proceduresGrid.AddColumn("PublishedTime", "Published");
        proceduresGrid.AddColumn("VersionNumber", "Version");
        proceduresGrid.AddColumn("Owner");
        proceduresGrid.AddColumn("Description");
        proceduresGrid.AddColumn("Type", "File type");
        proceduresGrid.AddColumn("EworkVersion", "e-Work version");
        proceduresGrid.AddColumn("Size", "Size (in bytes)");
        proceduresGrid.AutosizeColumns();
      }
    }
	}
}

